using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace NET.Library.Data
{
    /// <summary>
    /// DBHelper object.
    /// </summary>
    public class DBHelper
    {
        #region Enumerations
        private enum DBInt : int
        {
            Default = 0
        }
        #endregion

        #region Internal Methods
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object">Returns the default value of the DBInt enumeration as a decimal type if the object is null 
        /// or the decimal value of the object.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static decimal decimalValue(object Object)
        {
            return Object == DBNull.Value ? (decimal)DBInt.Default : Convert.ToDecimal(Object);
        }
        
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object">Returns an empty string if the object is null or the string value of the object.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static string stringValue(object Object)
        {
            return Object == DBNull.Value ? String.Empty : Object.ToString();
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object">Returns the default value of the DBInt enumeration as an integer type if the object is null 
        /// or the integer value of the object.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static int intValue(object Object)
        {
            return Object == DBNull.Value ? Convert.ToInt32(DBInt.Default) : Convert.ToInt32(Object);
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object">Returns the DateTime.MinValue constant if the object is null 
        /// or the DateTime value of the object.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static DateTime datetimeValue(object Object)
        {
            return Object == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(Object);
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object"></param>
        /// <returns>Returns false if the object is null or the boolean value of the object.</returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static bool boolValue(object Object)
        {
            return Object == DBNull.Value ? false : Convert.ToBoolean(Object);
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        internal static byte[] imageValue(object Object)
        {
            byte[] byteArray = new byte[1];
            byteArray[0] = (byte)DBInt.Default;
            return Object == DBNull.Value ? byteArray : (byte[])Object;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        internal static double doubleValue(object Object)
        {
            return Object == DBNull.Value ? (double)DBInt.Default : Convert.ToDouble(Object);
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Object"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        internal static Guid guidValue(object Object)
        {
            return Object == DBNull.Value ? Guid.Empty : (Guid)Object;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static object GetDBValue(IDataReader IDataReader, string FieldName)
        {
            //Get index of field name
            int i = IDataReader.GetOrdinal(FieldName);

            //Get field value
            return IDataReader.GetValue(i);
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SqlDataReader"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static object GetDBValue(SqlDataReader SqlDataReader, string FieldName)
        {
            //Get index of field name
            int i = SqlDataReader.GetOrdinal(FieldName);

            //Get field value
            return SqlDataReader.GetSqlValue(i);

        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns>Returns the value from the specified field as an object type.</returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        internal static object GetDBValue(DataRow DataRow, string FieldName)
        {
            //if (DataRow.Table.Columns.Contains(FieldName))
            //{
            //Get index of field name
            int i = DataRow.Table.Columns.IndexOf(FieldName);

            //Get field value
            return DataRow.ItemArray.GetValue(i);
            //}
            //else
            //{
            //    throw new Exception("The column " + FieldName + " does not exist");
            //}
        }
        
        #endregion

        #region Protected Internal Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objParam"></param>
        /// <remarks></remarks>
        /// <example></example>
        protected internal static void CheckParam(object objParam)
        {
            if (objParam == null)
                throw new ArgumentNullException(objParam.ToString());
        }
        
        #endregion

        /*************************************************************************
		 * SqlDatareaders
		 *************************************************************************/
        /// <summary>
        /// SQL String type
        /// *************************************************************************
        /// * Name        : GetDBString method
        /// *************************************************************************
        /// </summary>
        /// <param name="SqlDataReader">An open SqlDataReader</param>
        /// <param name="FieldName">The name of the String field to lookup in the SqlDataReader.</param>
        /// <returns>If the value of the field is DBNull, the value returned is String.Empty otherwise 
        /// the value of the field is returned as a string.</returns>
        /// <remarks></remarks>
        /// <example>string strMyFieldVal = GetDBString(SqlDataReader, "MyFieldName");</example>
        public static string GetDBString(SqlDataReader SqlDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return stringValue(GetDBValue(SqlDataReader, FieldName));
        }

        //SQL Int type
        /// <summary>
        /// *************************************************************************
        /// * Name        : GetDBInt method
        /// *************************************************************************
        /// </summary>
        /// <param name="SqlDataReader">An open SqlDataReader</param>
        /// <param name="FieldName">The name of the Integer field to lookup in the SqlDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        public static int GetDBInt(SqlDataReader SqlDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return intValue(GetDBValue(SqlDataReader, FieldName));
        }

        /// <summary>
        /// SQL Money type
        /// *************************************************************************
        /// * Name        : GetDBMoney method
        /// * Description : Returns Nothing if the datareader field
        /// *             : IsDBNull, otherwise returns the value
        /// *             : of the dataset field.
        /// * Syntax      : Resp = GetDBMoney(DataReader, Field, Default)
        /// * Parameters  : Resp        - the returned Decimal.
        /// *             : DataReader  - an open SQLDataReader.
        /// *             : Field       - the name of the Money field in the dataset.
        /// * Remarks     : If the value of the field is DBNull, the value returned is Nothing.
        /// * Example     : 
        ///*************************************************************************
        /// </summary>
        /// <param name="SqlDataReader">An open SqlDataReader</param>
        /// <param name="FieldName">The name of the Money field to lookup in the SqlDataReader.</param>
        /// <remarks></remarks>
        /// <example></example>
        public static decimal GetDBMoney(SqlDataReader SqlDataReader, string FieldName)//, decimal decDefault)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return decimalValue(GetDBValue(SqlDataReader, FieldName));
        }

        /// <summary>		
        /// SQL Decimal type
        /// *************************************************************************
        /// * Name        : GetDBDecimal method
        /// * Description : Returns Nothing if the datareader field
        /// *             : IsDBNull, otherwise returns the value
        /// *             : of the dataset field.
        /// * Syntax      : Resp = GetDBDecimal(SqlDataReader, FieldName, decDefault)
        /// * Parameters  : Resp        - the returned Decimal.
        /// *             : SqlDataReader  - an open SQLDataReader.
        /// *             : FieldName       - the name of the Decimal field in the dataset.
        /// * Remarks     : If the value of the field is Null, the value returned is the value specified by decDefault.
        /// * Example     : 
        /// *************************************************************************
        /// </summary>
        /// <param name="SqlDataReader">An open SqlDataReader</param>
        /// <param name="FieldName">The name of the Decimal field to lookup in the SqlDataReader.</param>
        /// <remarks></remarks>
        /// <example></example>
        public static decimal GetDBDecimal(SqlDataReader SqlDataReader, string FieldName)//, decimal decDefault)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return decimalValue(GetDBValue(SqlDataReader, FieldName));
        }

        //SQL Date type

        /*************************************************************************
        ' * Name        : GetDBDatetime method
        ' * Description : Returns Nothing if the datareader field
        ' *             : IsDBNull, otherwise returns the value
        ' *             : of the dataset field.
        ' * Syntax      : <Resp> = GetDBDatetime(<SqlDataReader>, <FieldName>, <dtDefault>)
        ' * Parameters  : <Resp> - the returned Date.
        ' *             : <SqlDataReader> - an open SQLDataReader.
        ' *             : <FieldName> - the name of the Date field in the sqldatareader.
        ' * Remarks     : If the value of the field is Null, the value returned is the value of dtDefault.
        ' * Example     : dteExpiryDate = GetDBDatetime(SqlDataReaderObject, FieldName, DefaulValue)
        ' *************************************************************************/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SqlDataReader">An open SqlDataReader</param>
        /// <param name="FieldName">The name of the DateTime field to lookup in the SqlDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        public static DateTime GetDBDateTime(SqlDataReader SqlDataReader, string FieldName)//, System.DateTime dtDefault)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return datetimeValue(GetDBValue(SqlDataReader, FieldName));
        }

        /*SQL Real Type??? Look into sql help
        'Public Shared Function GetDBReal(ByVal SqlDataReader As SqlDataReader, _
        '                                       ByVal FieldName As String) As Decimal
        '    Dim sinField As SqlTypes.sqlr = SqlDataReader.GetSqlDecimal(SqlDataReader.GetOrdinal(FieldName))
        '    If sinField.IsNull Then Return Nothing Else Return sinField.Value
        'End Function
        */

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SqlDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static byte[] GetDBImage(SqlDataReader SqlDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return imageValue(GetDBValue(SqlDataReader, FieldName));
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SqlDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static double GetDBDouble(SqlDataReader SqlDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return doubleValue(GetDBValue(SqlDataReader, FieldName));
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SqlDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static Guid GetDBGuid(SqlDataReader SqlDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(SqlDataReader);
            CheckParam(FieldName);

            //Get value
            return guidValue(GetDBValue(SqlDataReader, FieldName));
        }

        /*************************************************************************
        * Datarows
        *************************************************************************/
        //String type
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName">The name of the String field to lookup in the SqlDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        public static string GetDBString(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return stringValue(GetDBValue(DataRow, FieldName));
        }


        //Integer type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        public static int GetDBInt(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return intValue(GetDBValue(DataRow, FieldName));
        }

        //Date type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        public static DateTime GetDBDateTime(DataRow DataRow, string FieldName)//, System.DateTime dtDefault)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return datetimeValue(GetDBValue(DataRow, FieldName));
        }

        //Boolean type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName">The name of the field to lookup.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        public static bool GetDBBool(DataRow DataRow, string FieldName)//, bool blDefault)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            //object objVal = GetDBValue(DataRow, FieldName);

            return boolValue(GetDBValue(DataRow, FieldName));

            //			if (DataRow.IsNull(FieldName))
            //				return blDefault;
            //			int i = DataRow.Table.Columns.IndexOf(FieldName);
            //			return (bool)(DataRow.ItemArray.GetValue(i));
        }

        //Byte type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static byte[] GetDBImage(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return imageValue(GetDBValue(DataRow, FieldName));
        }

        //Decimal type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static decimal GetDBDecimal(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            return decimalValue(GetDBValue(DataRow, FieldName));
        }

        //Double Type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static double GetDBDouble(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return doubleValue(GetDBValue(DataRow, FieldName));
        }

        //Guid Type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DataRow"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static Guid GetDBGuid(DataRow DataRow, string FieldName)
        {
            //Check parameters
            CheckParam(DataRow);
            CheckParam(FieldName);

            //Get value
            return guidValue(GetDBValue(DataRow, FieldName));
        }

        /*************************************************************************************************************************************
         * IDatareaders
         ************************************************************************************************************************************/
        /// <summary>
        /// SQL String type
        /// *************************************************************************
        /// * Name        : GetDBString method
        /// *************************************************************************
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the String field to lookup in the IDataReader.</param>
        /// <returns>If the value of the field is DBNull, the value returned is String.Empty otherwise 
        /// the value of the field is returned as a string.</returns>
        /// <remarks></remarks>
        /// <example>string strMyFieldVal = GetDBString(IDataReader, "MyFieldName");</example>
        public static string GetDBString(IDataReader IDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return stringValue(GetDBValue(IDataReader, FieldName));
        }

        //SQL Int type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the Integer field to lookup in the IDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        public static int GetDBInt(IDataReader IDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return intValue(GetDBValue(IDataReader, FieldName));

        }

        /// <summary>
        /// SQL Money type
        /// *************************************************************************
        /// * Name        : GetDBMoney method
        /// * Description : Returns Nothing if the datareader field
        /// *             : IsDBNull, otherwise returns the value
        /// *             : of the dataset field.
        /// * Syntax      : Resp = GetDBMoney(DataReader, Field, Default)
        /// * Parameters  : Resp        - the returned Decimal.
        /// *             : DataReader  - an open IDataReader.
        /// *             : Field       - the name of the Money field in the dataset.
        /// * Remarks     : If the value of the field is DBNull, the value returned is Nothing.
        /// * Example     : 
        ///*************************************************************************
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the Money field to lookup in the IDataReader.</param>
        /// <remarks></remarks>
        /// <example></example>
        public static decimal GetDBMoney(IDataReader IDataReader, string FieldName)//, decimal decDefault)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return decimalValue(GetDBValue(IDataReader, FieldName));


        }

        /// <summary>		
        /// SQL Decimal type
        /// *************************************************************************
        /// * Name        : GetDBDecimal method
        /// * Description : Returns Nothing if the datareader field
        /// *             : IsDBNull, otherwise returns the value
        /// *             : of the dataset field.
        /// * Syntax      : Resp = GetDBDecimal(IDataReader, FieldName, decDefault)
        /// * Parameters  : Resp        - the returned Decimal.
        /// *             : IDataReader  - an open IDataReader.
        /// *             : FieldName       - the name of the Decimal field in the dataset.
        /// * Remarks     : If the value of the field is Null, the value returned is the value specified by decDefault.
        /// * Example     : 
        /// *************************************************************************
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the Decimal field to lookup in the IDataReader.</param>
        /// <remarks></remarks>
        /// <example></example>
        public static decimal GetDBDecimal(IDataReader IDataReader, string FieldName)//, decimal decDefault)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return decimalValue(GetDBValue(IDataReader, FieldName));
        }

        //SQL Date type

        /*************************************************************************
        ' * Name        : GetDBDatetime method
        ' * Description : Returns Nothing if the datareader field
        ' *             : IsDBNull, otherwise returns the value
        ' *             : of the dataset field.
        ' * Syntax      : <Resp> = GetDBDatetime(<IDataReader>, <FieldName>, <dtDefault>)
        ' * Parameters  : <Resp> - the returned Date.
        ' *             : <IDataReader> - an open IDataReader.
        ' *             : <FieldName> - the name of the Date field in the datareader.
        ' *             : <dtDefault> - the default datetime value to return for null records.
        ' * Remarks     : If the value of the field is Null, the value returned is the value of dtDefault.
        ' * Example     : DateTime dteExpiryDate = GetDBDatetime(IDataReaderObject, FieldName, DefaulValue)
        ' *************************************************************************/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the DateTime field to lookup in the IDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        public static DateTime GetDBDateTime(IDataReader IDataReader, string FieldName)//, System.DateTime dtDefault)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return datetimeValue(GetDBValue(IDataReader, FieldName));
        }

        //Boolean type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader">An open IDataReader</param>
        /// <param name="FieldName">The name of the field to lookup in the IDataReader.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example></example>
        ///----------------------------------------------------------------------------------
        public static bool GetDBBool(IDataReader IDataReader, string FieldName)//, bool blDefault)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            //object objVal = GetDBValue(DataRow, FieldName);

            return boolValue(GetDBValue(IDataReader, FieldName));

            //			if (DataRow.IsNull(FieldName))
            //				return blDefault;
            //			int i = DataRow.Table.Columns.IndexOf(FieldName);
            //			return (bool)(DataRow.ItemArray.GetValue(i));
        }

        //Image Type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static byte[] GetDBImage(IDataReader IDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return imageValue(GetDBValue(IDataReader, FieldName));
        }

        //Double Type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static double GetDBDouble(IDataReader IDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return doubleValue(GetDBValue(IDataReader, FieldName));
        }

        //Guid Type
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDataReader"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static Guid GetDBGuid(IDataReader IDataReader, string FieldName)
        {
            //Check parameters
            CheckParam(IDataReader);
            CheckParam(FieldName);

            //Get value
            return guidValue(GetDBValue(IDataReader, FieldName));
        }
    }
}
